﻿using Ledict.ConditionExtract.Base;
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Ledict.ConditionExtract.Frm.DataProcess;
using Ledict.Utility.Helper;
using Ledict.ConditionExtract.Frm;
using Ledict.ConditionExtract.Frm.NodeTree;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.Model;
using System.Collections.Generic;
using System.Linq;

namespace Ledict.ConditionExtract
{
    /// <summary>
    /// 主窗体
    /// </summary>
    public partial class MainForm : BaseForm
    {
        #region 构造函数
        //加载皮肤
        //Sunisoft.IrisSkin.SkinEngine skin = new Sunisoft.IrisSkin.SkinEngine();
        public MainForm()
        {
            InitializeComponent();

            #region 皮肤（未用）
            //add by zhangpeng 
            //var isLoadSkin = string.IsNullOrEmpty(ConfigHelper.AppSettings("IsLoadSkin")) ? "0" : ConfigHelper.AppSettings("IsLoadSkin");
            //if (isLoadSkin == "1")
            //{
            //    //加载皮肤
            //    var skinPath = System.Environment.CurrentDirectory + "\\Skin\\" + ConfigHelper.AppSettings("SkikName");
            //    skin.SkinFile = skinPath;
            //    //设置皮肤全局
            //    skin.SkinAllForm = true;
            //} 
            #endregion
        }
        #endregion

        #region 加载事件
        private void MainForm_Load(object sender, EventArgs e)
        {
            var rectangle = Screen.GetWorkingArea(this);
            this.Size = new Size(rectangle.Width, rectangle.Height);
            this.Location = rectangle.Location;
            //程序版本
            this.Text = ConfigHelper.AppSettings("Version") + "表述情形提取工具" + AssemblyVersion;
        }
        #endregion

        #region 获取属性中的程序版本
        public string AssemblyVersion
        {
            get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
        }
        #endregion

        #region 表述库加工
        /// <summary>
        /// 表述库加工
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToExpressionStorage_Click(object sender, EventArgs e)
        {
            ExpressionProcess es = ExpressionProcess.Default;
            ShowForm(es);
        }
        #endregion

        #region 要素分析
        /// <summary>
        /// 要素分析
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 要素分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //ElementAnalyze ea = ElementAnalyze.Default;
            ElementAnalyzeNew ea = ElementAnalyzeNew.Default;
            ShowForm(ea);
        }
        #endregion

        #region 基础词库
        /// <summary>
        /// 基础词库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 基础词库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WB_Manage_Base ea = WB_Manage_Base.Default;
            ShowForm(ea);
        }
        #endregion

        #region 同义词库
        /// <summary>
        /// 同义词库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 同义词库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WB_Manage_Synonyms ea = WB_Manage_Synonyms.Default;
            ShowForm(ea);
        }
        #endregion

        #region 刑事数据处理
        private void 刑事数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CrimeDataProcess dp = CrimeDataProcess.Default;
            ShowForm(dp);
        }
        #endregion

        #region 民事数据处理
        private void 民事数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //DataProcess dp = DataProcess.Default;
            //ShowForm(dp);
            CivilDataProcess dp = CivilDataProcess.Default;
            ShowForm(dp);
        }
        #endregion

        #region 修改密码
        private void 修改密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmUpdatePassWord objUpdatePassWord = new FrmUpdatePassWord();
            objUpdatePassWord.ShowDialog();
        }
        #endregion

        #region 关于
        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAbout frm = new FrmAbout();
            // Form3 frm = new Form3();
            frm.ShowDialog();
        }
        #endregion

        #region 刑事数据处理新
        private void 刑事数据新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CrimeDataProcessNew dp = CrimeDataProcessNew.Default;
            ShowForm(dp);
        }
        #endregion

        #region 实体法
        private void 实体法ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutLaw1 ea = AboutLaw1.Default;
            ShowForm(ea);
        }
        #endregion

        #region 程序法
        private void 程序法ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutLaw2 ea = AboutLaw2.Default;
            ShowForm(ea);
        }
        #endregion

        #region 民事数据新
        private void 民事数据新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CivilDataProcessNew1 dp = CivilDataProcessNew1.Default;
            ShowForm(dp);
        }
        #endregion

        #region 节点树案由
        private void 案由ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NodeTree nt = NodeTree.Instance;
            ShowForm(nt);
        }
        #endregion

        #region 节点树要素中心
        private void 要素中心ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ElementsConfig ec = ElementsConfig.Instance;
            //NodeTree1 nt = NodeTree1.Instance;
            ShowForm(ec);
        }
        #endregion

        #region 争议焦点分析
        private void 争议焦点分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //争议焦点分析
            NodeTreeAnalysis nt = NodeTreeAnalysis.Instance;
            ShowForm(nt);
        }
        #endregion

        private void 法规配置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //AboutLaw3 ea = AboutLaw3.Default;
            //ShowForm(ea);
        }

        private void 民事数据智能数据部ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CivilDataProcessAnalysis dp = CivilDataProcessAnalysis.Default;
            ShowForm(dp);
        }

        /// <summary>
        /// 宁夏违法行为及违法情形规则迁移
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 规则迁移工作ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //逻辑：获取两个大节点下的数据 然后按照名称进行比对 把名称相同的旧节点的RegexInfoCode赋给新节点的RegexInfoCode
            IList<SYS_CaseCause> sysCaseCauses= SqlManage.sqlServerJudgeDocSystem.Select<SYS_CaseCause>().Where(x => x.AllParentId.Contains("CC2111031200370001") && (x.CC_NodeType == 29 || x.CC_NodeType == 32))
                .ToList(x => new SYS_CaseCause { CC_ID = x.CC_ID, CC_Name = x.CC_Name });
            List<SYS_CaseCause> sysCaseCausesNX = SqlManage.sqlServerJudgeDocSystem.Select<SYS_CaseCause>().Where(x => x.AllParentId.Contains("CC2306261513000001") && (x.CC_NodeType == 29 || x.CC_NodeType == 32))
                .ToList(x => new SYS_CaseCause { CC_ID = x.CC_ID, CC_Name = x.CC_Name });
            if (sysCaseCauses.Count > 0&&sysCaseCausesNX.Count>0)
            {
                sysCaseCausesNX.ForEach(x =>
                {
                    string ccName = x.CC_Name;
                    SYS_CaseCause cc = sysCaseCauses.Where(a => a.CC_Name == ccName).FirstOrDefault();
                    if (cc!=null&&!string.IsNullOrEmpty(cc.CC_ID))
                    {
                        var expressNew = SqlManage.sqlServerJudgeDocSystem.Select<SysExpressSource>().Where(a => a.CC_ID == x.CC_ID).ToList(a=>new SysExpressSource {CC_ID=a.CC_ID, CC_RegexInfoCode=a.CC_RegexInfoCode });
                        var express = SqlManage.sqlServerJudgeDocSystem.Select<SysExpressSource>().Where(a => a.CC_ID == cc.CC_ID).ToList(a => new SysExpressSource { CC_ID = a.CC_ID, CC_RegexInfoCode = a.CC_RegexInfoCode });
                        if (express != null && expressNew != null)
                        {
                            string cOld = express.First().CC_RegexInfoCode;
                            string cNew = expressNew.First().CC_RegexInfoCode;
                            if (!string.IsNullOrEmpty(cOld))
                            {
                                int test = SqlManage.sqlServerJudgeDocSystem.Update<SysExpressSource>().Set(a => a.CC_RegexInfoCode == cOld).Where(a => a.CC_ID == x.CC_ID).ExecuteAffrows();
                            }
                        }
                    }
                });
            }

          
        }

        /// <summary>
        /// 生成CCID菜单选项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 生成CCIDToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CreateCCIDcs create = new CreateCCIDcs();
            create.ShowDialog();
        }

        private void 信息单元比对功能开发ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RegexManage rm = new RegexManage();
            rm.ShowDialog();
        }
    }
}
